{extend name="./app/admin/view/main.html" /}
{block name="title"}
{assign name="itemName" value="站点" /}
超级站点 - {/block}
{block name="style"}
<style>
    .ivu-modal-close {
        z-index: 999;
    }
</style>
{/block}
{block name="main"}
<header class="nicemip-container-header">
    <div class="float-left header-group">
        <h4 class="title">系统</h4> <h5 class="sub-title">超级站点</h5>
    </div>
    <button type="button" class="pull-right ivu-btn ivu-btn-primary ivu-btn-circle m-l-lg" @click='itemAdd'>
        <span>添加{$itemName}</span>
    </button>
</header>

<main class="nicemip-container-body" style="height: calc(100% - 50px)">
    <section class="nice-box">
        <section class="nice-box-body">
            <!--内容列表-->
            <section class="diy-table-list" v-cloak>
                <div class="diy-table-item diy-table-item-header">
                    <ul class="list-unstyled row">
                        <li class="col-md-3"><span>ID</span></li>
                        <li class="col-md-2"><span>网址</span></li>
                        <li class="col-md-2"><span>类型</span></li>
                        <li class="col-md-2"><span>模板</span></li>
                        <li class="col-md-2"><span>操作</span></li>
                    </ul>
                </div>
                <div v-if='itemList.length' class="diy-table-body">
                    <div class="diy-table-item" v-for='item in itemList' >
                         <ul class="list-unstyled row">
                            <li class="col-md-3"><span>{{item.id}}</span></li>
                            <li class="col-md-2 over-h-e"><span>{{item.http_type}}{{item.domain}}</span></li>
                            <li class="col-md-2"><span>{{item.type}}</span></li>
                            <li class="col-md-2"><span>{{item.template}}</span></li>
                            <li class="col-md-2">
                                <a @click='itemDel(item)' :disabled='item.disabled'>删除</a>
                                <a @click='itemEdit(item)' class="ml-1">修改</a>
                                <a @click='clickSetting(item)' class="ml-1">设置</a>
                            </li>
                         
                        </ul>
                    </div>
                </div>
                <div class="no-block" v-else>
                    <Icon type="ios-filing-outline"></Icon>
                    <p>暂无数据</p>
                </div>
            </section>
            <!--内容列表结束-->
        </section>
    </section>
     <Modal :title="dialogItemTitle" size="small" v-model='dialogItemStatus' v-cloak>
            <i-form :model="item" :rules="itemRules" ref="item" :label-width="80" >
                    <Form-item label="域名" prop="domain">
                        <i-input v-model="item.domain" :disabled='item.disabled' placeholder="www.nicemip.com">
                        <i-select v-model="item.httpType" slot="prepend" style="width: 80px">
                            <i-option value="http://">http://</i-option>
                            <i-option value="https://">https://</i-option>
                        </i-select>
                        </i-input>
                    </Form-item>
                    <Form-item label="类型">
                        <i-select v-model="item.type" style="width: 120px">
                            <i-option value="PC">PC</i-option>
                            <i-option value="M">M</i-option>
                            <i-option value="MIP">MIP</i-option>
                            <i-option value="AMP" disabled>AMP</i-option>
                            <i-option value="other">other</i-option>
                        </i-select>
                    </Form-item>
                    <Form-item label="数据ID">
                        <i-input type='number' v-model="item.data_id" placeholder="数字" style="width: 120px"></i-input>
                    </Form-item>
                    <Form-item label="模板">
                        <i-select v-model="item.template" style="width: 300px">
                            <i-option v-for='item in templateList' :value="item.fileName">{{item.fileName}}</i-option>
                        </i-select>
                    </Form-item>
            </i-form>
            <div slot="footer" class="dialog-footer">
                <i-button @click="dialogItemStatus = false">取 消</i-button>
                <i-button type="primary" @click="itemPost('item')">确 定</i-button>
            </div>
        </Modal>
</main>

<Modal size="small" v-model='settingModelStatus' v-cloak width='1000'>
    
    <Tabs :animated='false' style='height: 400px;'>
        <Tab-Pane label="关键词描述" name="name1">
            
            <div class="row">
                <div class="col-md-6">
                    <i-form label-position="top">
                        <Form-item label="网站名称">
                            <i-input v-model="setting.siteName"></i-input>
                        </Form-item>
                        <Form-item label="DIY首页全标题">
                            <i-input v-model="setting.diySiteName"></i-input>
                        </Form-item>
                        <Form-item label="网站关键词">
                            <i-input type="textarea" v-model="setting.keywords"></i-input>
                        </Form-item>
                        <Form-item label="网站描述">
                            <i-input type="textarea" v-model="setting.description"></i-input>
                        </Form-item>
                    </i-form>
                </div>
                <div class="col-md-6">
                    <i-form label-position="top">
                        <Form-item label="网站副标题">
                            <i-input v-model="setting.indexTitle" placeholder=" - 国内最大的互联网创业交流社区"></i-input>
                        </Form-item>
                        <Form-Item label="ICP备案号">
                            <i-input v-model="setting.icp"></i-input>
                        </Form-Item>
                        <Form-Item label="流量统计代码">
                            <i-input type="textarea" v-model="setting.statistical"></i-input>
                        </Form-Item>
                    </i-form>
                </div>
            </div>
        </Tab-Pane>
        <Tab-Pane label="MIP推送" name="name2">
            <i-form label-position="top">
                <div class="row">
                    <div class="col-md-6">
                        <Form-item label="MIP引入提交接口">
                            <i-input v-model="setting.mipApi" placeholder="请到百度站长平台 移动专区->MIP引入 获取"></i-input>
                        </Form-item>
                    </div>
                    <div class="col-md-2">
                         <Form-item label="MIP自动推送">
                            <i-switch v-model="setting.mipAutoStatus">
                                <span slot="open">开</span>
                                <span slot="close">关</span>
                            </i-switch>
                        </Form-item>
                    </div>
                </div>
              
            </i-form>
        </Tab-Pane>
        <Tab-Pane label="AMP推送" name="name3">
            <i-form label-position="top">
                <div class="row">
                    <div class="col-md-6">
                        <Form-item label="AMP引入提交接口">
                            <i-input v-model="setting.ampApi" placeholder="请到百度站长平台 移动专区->AMP引入 获取"></i-input>
                        </Form-item>
                    </div>
                    <div class="col-md-2">
                         <Form-item label="AMP自动推送">
                            <i-switch v-model="setting.ampAutoStatus">
                                <span slot="open">开</span>
                                <span slot="close">关</span>
                            </i-switch>
                        </Form-item>
                    </div>
                </div>
              
            </i-form>
        </Tab-Pane>
        <Tab-Pane label="熊掌号" name="name4">
             <i-form label-position="top">
                <div class="row">
                    <div class="col-md-6">
                        <Form-item label="熊掌号ID">
                            <i-input v-model="setting.xiongZhangId"></i-input>
                        </Form-item>
                        <Form-item label="熊掌号新增接口">
                            <i-input v-model="setting.xiongZhangNewApi"></i-input>
                        </Form-item>
                        <Form-item label="熊掌号历史接口">
                            <i-input v-model="setting.xiongZhangOldApi"></i-input>
                        </Form-item>
                    </div>
                    <div class="col-md-2">
                         <Form-item label="熊掌号模式">
                            <i-switch v-model="setting.xiongZhangStatus">
                                <span slot="open">开</span>
                                <span slot="close">关</span>
                            </i-switch>
                        </Form-item>
                        <Form-item label="熊掌号自动推送">
                            <i-switch v-model="setting.xiongZhangNewAutoStatus">
                                <span slot="open">开</span>
                                <span slot="close">关</span>
                            </i-switch>
                        </Form-item>
                    </div>
                </div>
            </i-form>
        </Tab-Pane>
        <Tab-Pane label="原创提交" name="name5">
            <i-form label-position="top">
                <div class="row">
                    <div class="col-md-6">
                        <Form-item label="原创提交接口">
                            <i-input v-model="setting.yuanChuangApi"></i-input>
                        </Form-item>
                    </div>
                    <div class="col-md-2">
                       <Form-item label="原创自动推送">
                            <i-switch v-model="setting.yuanChuangAutoStatus">
                                <span slot="open">开</span>
                                <span slot="close">关</span>
                            </i-switch>
                        </Form-item>
                    </div>
                </div>
            </i-form>
        </Tab-Pane>
        <Tab-Pane label="链接提交" name="name6">
            <i-form label-position="top">
                <div class="row">
                    <div class="col-md-6">
                        <Form-item label="链接提交接口">
                            <i-input v-model="setting.linkApi"></i-input>
                        </Form-item>
                    </div>
                    <div class="col-md-2">
                       <Form-item label="链接自动推送">
                            <i-switch v-model="setting.linkAutoStatus">
                                <span slot="open">开</span>
                                <span slot="close">关</span>
                            </i-switch>
                        </Form-item>
                    </div>
                </div>
            </i-form>
        </Tab-Pane>
        <Tab-Pane label="百度站内搜索" name="name7">
            <i-form label-position="top">
                <div class="row">
                    <div class="col-md-6">
                        <Form-item label="百度站内搜索Key">
                            <i-input v-model="setting.baiduSearchKey"></i-input>
                        </Form-item>
                        <Form-item label="百度站内搜索sitemap">
                            <i-input v-model="setting.baiduSearchSiteMap" disabled></i-input>
                        </Form-item>
                    </div>
                    <div class="col-md-6">
                    </div>
                </div>
            </i-form>
        </Tab-Pane>
    </Tabs>
  
<div slot="footer" class="dialog-footer">
    <i-button @click="settingModelStatus = false">取 消</i-button>
    <i-button type="primary" @click="onSubmitSetting()">确 定</i-button>
</div>
</Modal>


{/block}
    
{block name="javascript"}
{__block__}
<script>
    new Vue({
        el: '#app',
        data: {
            itemName: '{$itemName}',
            itemList: [], 
            templateList: [],
            
            item: {
                id: '',
                httpType: '',
                domain: '',
                type: '',
                data_id: 0,
                template: '',
                disabled: false,
            },
            dialogItemTitle: '添加{$itemName}',
            dialogItemStatus: false,
            
            itemRules: {
                domain: [{
                    required: true,
                    message: '请输入域名',
                    trigger: 'blur'
                }]
            },
            //弹出
            settingModelStatus: false,
            settingModelTitle: '',
            settingModelId: '',
            setting: '',
            siteInfo: '',
            
            pagination: {
                currentPage: 1,
                limit: 10,
                total: this.total,
            },
        },
        watch: {
             
        },
        mounted() {
            this.getItemList();
            this.getTemplateList();
        },
        methods: {
            clickSetting(item) {
                this.settingModelId = item.id;
                this.settingModelTitle = '设置';
                this.getDomainSites();
            },
            onSubmitSetting: function() {
                this.$nicemip.ajax('{$domain}/setting/ApiAdminDomainSettings/itemEdit', {
                    id: this.settingModelId,
                    setting: JSON.stringify(this.setting),
                }).then(res => {
                    if(res.code == 1) {
                        this.$Message.success('保存成功');
                        this.getDomainSites();
                    }
                });
            },
            getDomainSites() {
                this.$nicemip.ajax('{$domain}/setting/ApiAdminDomainSites/domainSitesFind', {
                    id: this.settingModelId,
                }).then(res => {
                    this.loading = false;
                    if(res.code == 1) {
                        this.siteInfo = res.data;
                        this.getSettingData();
                    }
                 });
            },
            getSettingData: function() {
                this.$nicemip.ajax('{$domain}/setting/ApiAdminDomainSettings/itemFind', {
                    id: this.settingModelId,
                }).then(res => {
                    this.loading = false;
                    if(res.code == 1) {
                        var temp = res.data;
                         
                        if (temp.mipAutoStatus) {
                            temp.mipAutoStatus = true;
                        } else {
                            temp.mipAutoStatus = false;
                        }
                        
                        if (temp.ampAutoStatus) {
                            temp.ampAutoStatus = true;
                        } else {
                            temp.ampAutoStatus = false;
                        }
                        
                        if (temp.xiongZhangStatus) {
                            temp.xiongZhangStatus = true;
                        } else {
                            temp.xiongZhangStatus = false;
                        }
                        
                        if (temp.xiongZhangNewAutoStatus) {
                            temp.xiongZhangNewAutoStatus = true;
                        } else {
                            temp.xiongZhangNewAutoStatus = false;
                        }
                        
                        if (temp.yuanChuangAutoStatus) {
                            temp.yuanChuangAutoStatus = true;
                        } else {
                            temp.yuanChuangAutoStatus = false;
                        }
                        
                        if (temp.linkAutoStatus) {
                            temp.linkAutoStatus = true;
                        } else {
                            temp.linkAutoStatus = false;
                        }
                        
                        temp.baiduSearchSiteMap = '/baiduSitemapPc.xml';
                        
                        this.setting = temp;
                        this.settingModelStatus = true;
                    }
                });
            },
            
            itemAdd() {
                this.item.id = '';
                this.item.dialogItemTitle = '添加{$itemName}';
                this.item.domain = '';
                this.item.httpType = 'http://';
                this.item.type = 'PC';
                this.item.data_id = 0;
                this.item.template = 'default';
                this.item.disabled = false;
                this.dialogItemStatus = true;
            },
            itemDel(item) {
                this.$Modal.confirm({
                    title: '消息提示',
                    content: '<p>确定删除么？删除后不可恢复</p>',
                    onOk: () => {
                        _this = this;
                        this.$nicemip.ajax('{$domain}/setting/ApiAdminDomainSites/itemDel', {
                            id: item.id,
                        }).then(res => {
                            if(res.code == 1) {
                                this.$Message.success('删除成功');
                                this.getItemList();
                            }
                        });
                    },
                    onCancel: () => {
                    }
                });
            },
            itemEdit(item) {
                this.item.id = item.id;
                this.item.dialogItemTitle = '修改{$itemName}';
                this.item.domain = item.domain;
                this.item.httpType = item.httpType;
                this.item.type = item.type;
                this.item.data_id = item.data_id ? item.data_id : 0;
                this.item.template = item.template;
                this.item.disabled = item.disabled;
                this.dialogItemStatus = true;
            },
            itemPost(val) {
                this.$refs[val].validate((valid) => {
                    if(valid) {
                        if (this.item.id) {
                            this.$nicemip.ajax('{$domain}/setting/ApiAdminDomainSites/itemEdit', {
                                id: this.item.id,
                                httpType: this.item.httpType,
                                domain: this.item.domain,
                                template: this.item.template,
                                data_id: this.item.data_id,
                                type: this.item.type,
                            }).then(res => {
                                if(res.code == 1) {
                                    this.$Message.success('修改成功');
                                    this.getItemList();
                                    this.dialogItemStatus = false;
                                }
                            });
                        } else {
                            this.$nicemip.ajax('{$domain}/setting/ApiAdminDomainSites/itemAdd', {
                                title: this.item.title,
                                httpType: this.item.httpType,
                                domain: this.item.domain,
                                data_id: this.item.data_id,
                                template: this.item.template,
                                type: this.item.type,
                            }).then(res => {
                                if(res.code == 1) {
                                    this.$Message.success('添加成功');
                                    this.getItemList();
                                    this.dialogItemStatus = false;
                                }
                            });
                        }
                        
                    }
                });
            },
            getItemList() {
                this.loading = true;
                this.$nicemip.ajax('{$domain}/setting/ApiAdminDomainSites/itemSelect', {
                    page: this.pagination.currentPage,
                    limit: this.pagination.limit,
                }).then(res => {
                    this.itemList = [];
                    if(res.code == 1) {
                        var itemList = res.data.itemList;
                        for (var i = 0; i < itemList.length; i++) {
                        	itemList[i].httpType = itemList[i].http_type;
                        	if ('{$domain}' == itemList[i].httpType + itemList[i].domain && mipGlobal.mipInfo.superSites) {
                        	    itemList[i].disabled = true;
                        	} else {
                        	    itemList[i].disabled = false;
                        	}
                        }
                        this.itemList = itemList;
                        this.pagination.total = res.data.total;
                    }
                    this.loading = false;
                });
            },
            
            getTemplateList() {
                var _this = this;
                this.$nicemip.ajax('{$domain}/setting/ApiAdminTemplate/templateList', {
                }).then(res => {
                    if(res.code == 1) {
                        var templateList = res.data;
                        this.templateList = templateList;
                    }
                });
            },
        }
    })
  </script>
{/block}